package com.addcn.android.design591.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.addcn.android.design591.R;
import com.addcn.android.design591.bean.DesignImageBean;
import com.addcn.android.design591.utils.L;
import com.addcn.android.design591.viewholder.DesignImageViewHolder;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

/**
 * Created by xuge on 2017/1/20.
 * 图库设计适配器
 */

public class DesignImageAdapter extends RecyclerView.Adapter<DesignImageViewHolder> {
    private Context context;
    private LayoutInflater layoutInflater;
    private ArrayList<DesignImageBean.DataBean.WorksListBean> arrayList;
    public OnItemClickListener onItemClickListener;


    public DesignImageAdapter(Context context, ArrayList<DesignImageBean.DataBean.WorksListBean> arrayList) {
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
        this.arrayList = arrayList;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }


    @Override
    public DesignImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.designimage_item, null);
        DesignImageViewHolder designImageViewHolder = new DesignImageViewHolder(view);
        return designImageViewHolder;
    }

    @Override
    public void onBindViewHolder(final DesignImageViewHolder holder, final int position) {
        if (onItemClickListener != null) {
            holder.designimage_item_image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onItemClickListener.onItemClick(holder.designimage_item_image, position);
                }
            });
        }
        DesignImageBean.DataBean.WorksListBean worksListBean=arrayList.get(position);

        Glide.with(context)
                .load(worksListBean.cover_img)
                .placeholder(R.mipmap.jyf)
                .into(holder.designimage_item_image);

        holder.design_item_text.setText(worksListBean.works_title);
    }


    @Override
    public int getItemCount() {
        return arrayList.size();
    }


    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }
}
